Ext.namespace("Ext.ux");
Ext.ux.Radio = function(a) {
	Ext.ux.Radio.superclass.constructor.call(this, a);
	this.group = a.group;
	this.value = a.value;
	this.disabled = a.disabled
};
Ext.extend(Ext.ux.Radio, Ext.form.Radio, {
	onRender : function(b, a) {
		Ext.ux.Radio.superclass.onRender.call(this, b, a);
		if (this.el && this.el.dom) {
			this.el.dom.value = this.value
		}
		this.on("check", this.onCheck)
	},
	clearInvalid : function() {
		this.group.clearInvalid()
	},
	markInvalid : function(a) {
		this.group.markInvalid(a)
	},
	onClick : function() {
		if (this.el.dom.checked != this.checked) {
			this.group.setValue(this.value)
		} else {
			if (this.group.getValue() == this.value) {
				this.checked = false
			}
		}
	},
	setValue : function(a) {
		this.checked = (a === true || a === "true" || String(a).toLowerCase() == "on");
		if (this.el && this.el.dom) {
			this.el.dom.checked = this.checked;
			this.el.dom.defaultChecked = this.checked;
			this.group.el.dom.value = (this.checked ? this.value : "")
		}
	},
	onCheck : function(b, c) {
		Ext.log("radiao change!");
		if (c) {
			var a = this.group.getValue();
			this.group.onChange(this.group, a, this.getValue())
		}
	},
	getValue : function() {
		if (this.rendered) {
			return this.el.dom.value
		}
		return false
	}
});
Ext.ux.RadioGroup = function(a) {
	this.radios = a.radios;
	this.defaultValue = (a.defaultValue == "" ? "" : a.defaultValue);
	Ext.ux.RadioGroup.superclass.constructor.call(this, a)
};
Ext.extend(Ext.ux.RadioGroup, Ext.form.Field, {
			defaultAutoCreate : {
				tag : "input",
				type : "hidden"
			},
			onRender : function(c, a) {
				Ext.ux.RadioGroup.superclass.onRender.call(this, c, a);
				this.wrap = this.el.wrap({
							cls : "x-form-check-wrap"
						});
				if (this.radios && this.radios instanceof Array) {
					this.els = new Array();
					this.els[0] = this.el;
					for (var b = 0; b < this.radios.length; b++) {
						var d = this.radios[b];
						this.els[b] = new Ext.ux.Radio(Ext.apply({}, {
									renderTo : this.wrap,
									hideLabel : true,
									disabled : this.disabled,
									group : this
								}, d));
						if (this.horizontal) {
							this.els[b].el.up("div.x-form-check-wrap")
									.applyStyles({
												display : "inline",
												"padding-left" : "5px"
											})
						}
					}
					if (this.hidden) {
						this.hide()
					}
				}
				this.setDefaultValue()
			},
			initValue : function() {
				if (this.value !== undefined) {
					this.el.dom.value = this.value
				} else {
					if (this.el.dom.value.length > 0) {
						this.value = this.el.dom.value
					}
				}
			},
			getValue : function() {
				if (this.rendered) {
					return this.el.dom.value
				}
				return false
			},
			setValue : function(a) {
				var c = this.getValue();
				for (var b = 0; b < this.els.length; b++) {
					if (this.els[b].value == a && (c != a)) {
						this.els[b].setValue(true)
					} else {
						this.els[b].setValue(false)
					}
				}
				if (c === a) {
					this.el.dom.value = ""
				} else {
					this.el.dom.value = a
				}
				this.fireEvent("change", this.group, c, a)
			},
            setDisabled:function(value){
                for (var a = 0; a < this.els.length; a++) {
                        this.els[a].setDisabled(value);
                }
            },
			setDefaultValue : function() {
				for (var a = 0; a < this.els.length; a++) {
					if (this.els[a].value == this.defaultValue) {
						this.els[a].setValue(true);
						return
					} else {
						if (a < this.els.length - 1) {
							this.els[a].setValue(false)
						} else {
						}
					}
				}
			},
           setDefValue : function(v) {
				for (var a = 0; a < this.els.length; a++) {
					if (this.els[a].value == v) {
						this.els[a].setValue(true);
						return
					} else {
						if (a < this.els.length - 1) {
							this.els[a].setValue(false)
						} else {
						}
					}
				}
			},
			onDestroy : function() {
				if (this.radios && this.radios instanceof Array) {
					var b = this.radios.length;
					for (var a = 1; a < b; a++) {
						this.els[a].destroy()
					}
				}
				if (this.wrap) {
					this.wrap.remove()
				}
				Ext.ux.RadioGroup.superclass.onDestroy.call(this)
			},
			onChange : function(a, b) {
				this.fireEvent("change", this, a, b)
			}
		});
Ext.reg("radiogroup", Ext.ux.RadioGroup);